import java.sql.Timestamp;

import com.demo.inheritance.tableperclasshierarcy.ParentLoginDetailsDTO;
import com.demo.inheritance.tableperclasshierarcy.RemoteUserDetailsDTO;
import com.demo.service.dao.HibernateDaoService;


public class HibernateInheritanceMain {

	 HibernateDaoService daoService=new HibernateDaoService();
	
	public static void main(String[] args) {
		
		HibernateInheritanceMain inheritanceMain=new HibernateInheritanceMain();
		 
		
		inheritanceMain.insertTablePerClassHierarchyDetails();
		 
		 
		 
		 System.out.println("main method executed..");
		
		 inheritanceMain.fetchObject();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 *  
	 *  
	 *  this belongs to table per class hierarcy
	 *  @param  none
	 *  @return void
	 *  @author rajeev
	 *  @since v1.1
	 *  
	 */
	
	public void insertTablePerClassHierarchyDetails(){
		
		RemoteUserDetailsDTO detailsDTO=new RemoteUserDetailsDTO();
		ParentLoginDetailsDTO parentLoginDetailsDTO=new ParentLoginDetailsDTO();
        
		detailsDTO.setFullName("Common User");
		detailsDTO.setLocked(false);
        detailsDTO.setUsername("demoadmin");
        detailsDTO.setCreatedTime(new Timestamp(System.currentTimeMillis()));

        parentLoginDetailsDTO.setFullName("Parent User full name");
        parentLoginDetailsDTO.setDob(new Timestamp(System.currentTimeMillis())); //1 jan 1970
        parentLoginDetailsDTO.setSchoolId(1);
        parentLoginDetailsDTO.setSessionTime(new Timestamp(System.currentTimeMillis()));

         daoService.insertNewRow(detailsDTO);
         daoService.insertNewRow(parentLoginDetailsDTO);
	}
	
	public void fetchObject(){
		
	    ParentLoginDetailsDTO  remoteUserDetailsDTO=(ParentLoginDetailsDTO)daoService.fetchObjectFromDatabase(RemoteUserDetailsDTO.class, 2);
		 
	       if(remoteUserDetailsDTO instanceof ParentLoginDetailsDTO){
	    	   System.out.println("this object belongs to parent logi");
	       }else {
	    	   System.out.println("still remote user..");
	       }
		
	}
	
}
